import 'package:second_hand/API/request_ways.dart';

import '../../data/shared_preferences_service.dart';

class AdminApiService{
  static const String baseUrl = "http://39.107.246.135:1224";
  static const int timeoutSeconds = 10;
  static Future<Map<String, dynamic>> login({required String username,required String password}){
    return Request.postRequest(path: '/admin/login',body: {'username':username,'password':password});
  }
  // 分页查询商品列表接口
  static Future<Map<String, dynamic>> searchGoods(int page) async {
    final token = await SharedPreferencesService.getAdminToken();
    if(token == null){
      return {'code': //todo
      '' , 'message': '未登录'};
    }
    final queryParams = {
      'page': page.toString(),
    };
    final response = await Request.getRequest(
        path: "/admin/item/list",
        header: {"Authorization": token},
        queryParams: queryParams
    );
    return response;
  }
  //商品通过审核
  static Future<Map<String,dynamic>> approveItem({required int itemId})async{
    final token=await SharedPreferencesService.getAdminToken();
    if(token==null){
      return {'code': //todo
      '' , 'message': '未登录'};
    }
    return Request.patchRequest(path: '/admin/item/review/$itemId',header: {'Authorization':token});
  }
  //商品未通过审核
  static Future<Map<String,dynamic>> rejectItem({required int itemId})async{
    final token=await SharedPreferencesService.getAdminToken();
    if(token==null){
      return {'code': //todo
      '' , 'message': '未登录'};
    }
    return Request.patchRequest(path: '/admin/item/reject/$itemId',header: {'Authorization':token});
  }
}